<template>
	<view class="deatil">
		<!-- 纯富文本 -->
		<richText :RichContent="query.content" v-if="type == 'plain'"></richText>
		<!-- 优惠券活动 -->
		<discountCoupon :swiperList="query.image_list" :tabsList="tabsList" :TabsCurrent="TabsCurrent" @changeTabs="changeTabs" @changeDraw="Draw"
			:popupList="!TabsCurrent?query.vip_coupon_list:query.coach_coupon_list" @toggle="toggles" v-else-if="type == 'coupon' || type == 'festival'"></discountCoupon>
		<!-- 门店VIP活动 -->
		<member :content="query.content" @shop="routeShop" @vip="routeVip" v-else-if="type == 'card'"></member>
		<!-- 购买课程 -->
		<PurchaseCourse :RichContent="courseContent"  v-else-if="type == 'course'"></PurchaseCourse>
	</view>
</template>

<script>
	import richText from './components/rich-text.vue'
	import discountCoupon from './components/discount-coupon.vue'
	import member from './components/member.vue'
	import PurchaseCourse from './components/Purchase-course.vue'
	import{
		main
	} from '@/api/activity.js'
	import{
		draw
	} from '@/api/home.js'
	export default {
		components: {
			richText,
			discountCoupon,
			member,
			PurchaseCourse,
		},
		data() {
			return {
				query:{},
				type:'',
				RichContent: '',
				courseContent:'',
				JoinContent:'',
				swiper: [],
				tabsList: [{
						name: 'VIP会员优惠'
					},
					{
						name: '私教课优惠'
					}
				],
				TabsCurrent: 0,
				popupList: [],
				ex:{}
			}
		},
		onLoad(e) {
			console.log('e', e);
			this.ex = e
			this.type = e.form
			
		},
		onShow() {
			this.getmain({param:this.ex.param})
		},
		mounted() {},
		methods: {
			Draw(item, index){
				console.log('item', item);
				draw({
					form:'coupon',
					coupon_id:item.coupon_id
				}).then(({data:res})=>{
					console.log('res', res);
					if(res.code == 1){
						if(!this.TabsCurrent){
							this.query.vip_coupon_list[index].is_draw = 1
						}else{
							this.query.coach_coupon_list[index].is_draw = 1
						}
					}
					
				})
			},
			routeVip(){
				uni.navigateTo({
					url:'/pageA/member/purchase?par=' + this.query.par
				})
				
			},
			routeShop(){
				uni.navigateTo({
					url:'/pageA/shop/particulars?shop_id=' + this.query.shop_id
				})
			},
			getmain(e){
				main(e).then(({data:res})=>{
					console.log('res', res);
					if(res.code == 1){
						this.query = res.data
						const obj = {}
						this.$u.mpShare = {
							path: 'pageB/activity/deatil?form=' + this.ex.form + '&param=' + this.ex.param, 
						}
					}else{
						this.$SHOWMODALMSG('', res)
					}
				})
			},
			changeTabs(index) {
				this.TabsCurrent = index
			},
			toggles(message){
				console.log('message', message);
				if(!this.TabsCurrent){
					this.$set(this.query.vip_coupon_list[message], 'open', !this.query.vip_coupon_list[message].open);
				}else{
					this.$set(this.query.coach_coupon_list[message], 'open', !this.query.coach_coupon_list[message].open);
				}
				
			},
		}
	}
</script>

<style lang="scss" scoped>
</style>